package com.aspose.cells;

import java.awt.Graphics2D;
import java.io.OutputStream;
import java.util.ArrayList;

public class SheetRender {
   private Workbook a;
   private Worksheet b;
   private ImageOrPrintOptions c;
   private zbuz d;
   private int e = 0;
   private ArrayList<Integer> f;

   public int getPageCount() {
      return this.e;
   }

   public void setPageCount(int value) {
      this.e = value;
   }

   public double getPageScale() {
      if (this.d.h.containsKey(this.b.getIndex())) {
         return (double)((zbmg)this.d.h.get(this.b.getIndex())).a;
      } else {
         PageSetup var1 = this.b.getPageSetup();
         return !var1.isPercentScale() && (var1.getFitToPagesTall() != 0 || var1.getFitToPagesWide() != 0) ? 1.0D : (double)((float)var1.getZoom() / 100.0F);
      }
   }

   public SheetRender(Worksheet worksheet, ImageOrPrintOptions options) throws Exception {
      this.a = worksheet.getWorkbook();
      this.b = worksheet;
      this.c = options;
      if (options.getImageFormat() == ImageFormat.getBmp()) {
         this.c.a(139273);
      }

      this.d = new zbuz(this.a);
      this.d.a = new com.aspose.cells.a.d.zat();
      if (worksheet.getPageSetup().getBlackAndWhite()) {
         this.c.e = true;
      }

      this.d.a(worksheet, this.c);
      if (this.d.c != null) {
         this.e = this.d.c.size();
      }

      this.f = new ArrayList();
   }

   public boolean toImage(int pageIndex, Graphics2D graphic) throws CellsException {
      float[] var3 = this.getPageSize(pageIndex);
      com.aspose.cells.b.a.b.zb var4 = new com.aspose.cells.b.a.b.zb(graphic, (int)Math.ceil((double)(var3[0] * 1.3333F)), (int)Math.ceil((double)(var3[1] * 1.3333F)));

      try {
         this.a(pageIndex);
         return this.d.a(pageIndex, (ImageOrPrintOptions)this.c, (com.aspose.cells.b.a.b.zi)var4);
      } catch (Exception var6) {
         throw new CellsException(7, var6.getMessage());
      }
   }

   public float[] getPageSize(int pageIndex) {
      zan var2 = (zan)this.d.c.get(pageIndex);
      float var3 = (float)var2.x[0];
      float var4 = (float)var2.x[1];
      return this.c.getImageFormat() == ImageFormat.getEmf() ? new float[]{var3, var4} : new float[]{var3 * (float)this.c.getHorizontalResolution() / 96.0F + 1.0F, var4 * (float)this.c.getVerticalResolution() / 96.0F + 1.0F};
   }

   public void toImage(int pageIndex, String fileName) throws Exception {
      this.a(pageIndex);
      this.d.a(pageIndex, fileName, this.c);
   }

   public void toImage(int pageIndex, OutputStream stream) throws Exception {
      this.a(pageIndex);
      com.aspose.cells.b.a.d.zj var3 = new com.aspose.cells.b.a.d.zj(stream);
      this.d.a(pageIndex, (ImageOrPrintOptions)this.c, (com.aspose.cells.b.a.d.zm)var3);
   }

   void a(int var1, com.aspose.cells.b.a.d.zm var2) throws Exception {
      this.d.a(var1, this.c, var2);
   }

   public void toPrinter(String PrinterName) throws Exception {
      this.d.g = true;
      zho var2 = new zho(PrinterName, this.d);
      var2.a();
   }

   public void toPrinter(String PrinterName, String JobName) throws Exception {
      this.d.g = true;
      zho var3 = new zho(PrinterName, JobName, this.d);
      var3.a();
   }

   private void a(int var1) throws Exception {
      if (var1 >= 0 && var1 < this.e) {
         if (!this.f.contains(var1)) {
            if (var1 != 0 && !this.f.contains(var1 - 1)) {
               int var2;
               for(var2 = var1 - 1; var2 >= 0 && !this.f.contains(var2); --var2) {
                  ;
               }

               for(int var3 = var2 + 1; var3 < var1; ++var3) {
                  this.f.add(var3);
                  this.d.a(var3, this.c);
               }

               this.f.add(var1);
            } else {
               this.f.add(var1);
            }
         }
      }
   }
}
